<template>
	<view class="home-container">
		<view class="home-top">
			<image src="../../static/img/grzx_bg.png"></image>
		</view>
		<view class="home-content">
			<view class="content-top">
				<view class="top-left">
					<view class="left-1">
						<image v-if="personInfo.userImage=='' || personInfo.userImage==null" src="../../static/touxiang-2.png"></image>
						<image v-else :src="personInfo.userImage"></image>
					</view>
					<view class="left-2">
						<view class="left-2-top">
							<view class="left-2-top-1">{{ personInfo.name }}</view>
							<view class="left-2-top-2">{{personInfo.userType}}</view>
						</view>
						<view class="left-2-bottom">部门:<text>{{ personInfo.groupName }}</text></view>
					</view>
				</view>
				<view class="top-right">
					<view class="top-right-1">晴</view>
					<view class="top-right-1">15°C</view>
				</view>
			</view>
			<view class="content-con1">
				<view class="content-con1-head">整体数据统计</view>
				<view class="content-con1-con">
					<view class="content-con1-con-item" v-for="(item,index) in HeadList" :key="index" @click="toPage(item.page)">
						<view class="item-top">
							<view class="item-top-img">
								<image mode="widthFix" :src="item.img"></image>
							</view>
							<view class="item-top-text">{{ item.text}}</view>
						</view>
						<view class="item-bottom">{{ item.num }}</view>
					</view>
				</view>
				<view class="content-con1-con2">
					<view class="content-con1-con2-item">
						<view class="item-top">{{submitEventNum}}</view>
						<view class="item-top">事件</view>
					</view>
					<view class="content-con1-con2-item">
						<view class="item-top">{{ targetXun }}</view>
						<view class="item-top">巡查</view>
					</view>
					<view class="content-con1-con2-item">
						<view class="item-top">{{ targetZou }}</view>
						<view class="item-top">走访</view>
					</view>
				</view>
			</view>
			<view class="content-con2">
				<view class="content-con2-head">
					<u-tabs name="cate_name" count="cate_count" :list="list" :is-scroll="false" :current="current" @change="change">
					</u-tabs>
				</view>
				<view class="none" v-if="bottomList.length == 0">暂无数据</view>
				<view class="content-con2-content">
					<view class="content-con2-content-item" v-for="(item,index) in bottomList" @click="handleGoInfo(item.id)" :key="index">
						<view class="item-top">{{ item.title }}</view>
						<view class="item-bottom">
							<view class="bottom-1">{{ item.listLeft }}</view>
							<view class="bottom-2">{{ item.listRight }}</view>
						</view>
					</view>
				</view>
			</view>
		</view>
		<zy-update theme="blue" :autocheckupdate="true" :h5preview="false" oldversion="1.3.0" :appstoreflag="false"
		 :updateurl="update_url"></zy-update>
		<u-popup v-model="midButton" mode="bottom" border-radius="30">
			<view class="midButton">
				<view class="midButton-head">选择您要添加的项目</view>
				<view class="midbutton-content">
					<view class="midbutton-content-item" v-for="(item,index) in midButtonList" :key="index" @click="handlemidButton(item.page)">
						<view class="item-top">
							<image :src="item.img"></image>
						</view>
						<view class="item-bottom">{{ item.text }}</view>
					</view>
				</view>
				<view class="midbutton-cacel" @click="midButton=false">取消</view>
			</view>
		</u-popup>
	</view>
</template>

<script>
	// import ZyUpdate from '../../components/zy-upgrade/zy-upgrade.vue'
	export default {
		data() {
			return {
				targetXun:0,
				targetZou:0,
				type: 0, 
				personInfo: {
					name: '',
					groupName: '',
					girderHeadImg: ''
				},//https://api.jumei666.com/api
				update_url: 'https://api.jumei666.com/api/api/app/getNewAppVersion',
				midButton: false,
				submitEventNum: 0,
				midButtonList: this.midButtonList,
				HeadList: [
					{
						img: '../../static/icon/loufang.png',
						text: '楼栋',
						num: '0',
						page: '../InformationCollection/InformationCollection-building/InformationCollection-building'
					},
					{
						img: '../../static/icon/fangwu.png',
						text: '房屋',
						num: '0',
						page: '../InformationCollection/House/House'
					},
					{
						img: '../../static/icon/xiaoqu.png',
						text: '小区',
						num: '0',
						page: '../InformationCollection/Courtyard/Courtyard'
					},
					{
						img: '../../static/icon/huji.png',
						text: '户籍',
						num: '0',
						page: '../InformationCollection/Domicile/Domicile'
					},
					{
						img: '../../static/icon/renkou.png',
						text: '人口',
						num: '0',
						page: '../InformationCollection/Population/Population'
					},
					{
						img: '../../static/icon/icon_key_personnel.png',
						text: '重点人员',
						num: '0',
						page: '../InformationCollection/keyPersonnel/keyPersonnel'
					},
					{
						img: '../../static/icon/qiye_h11.png',
						text: '企业',
						num: '0',
						page: '../InformationCollection/Company/Company'
					},
					{
						img: '../../static/icon/icon_hospital.png',
						text: '医院',
						num: '0',
						page: '../InformationCollection/Hospital/Hospital'
					},
					{
						img: '../../static/icon/xuexiaobeifen.png',
						text: '学校',
						num: '0',
						page: '../InformationCollection/School/School'
					},
					{
						img: '../../static/icon/dianpu.png',
						text: '店铺',
						num: '0',
						page: '../InformationCollection/Shop/Shop'
					},
					{
						img: '../../static/icon/h5.png',
						text: '公共设施',
						num: '0',
						page: '../InformationCollection/Part/Part'
					},
					// {
					// 	img: '../../static/icon/icon_road_railway_sections.png',
					// 	text: '铁路重点路段',
					// 	num: '0',
					// 	page: ''
					// },
				],
				list: [{
					cate_name: '待办事件',
					cate_count: 0
				}, {
					cate_name: '待巡查',
					cate_count: 0
				}, {
					cate_name: '待办任务',
					cate_count: 0
				}, {
					cate_name: '全部 >'
				}],
				current: 0,
				thingsList: [],
				bottomList: []
			}
		},
		// components: {
		// 	ZyUpdate
		// },
		onLoad() {
			uni.onTabBarMidButtonTap((e) => {
				this.midButton = true
			})
		},
		onShow() {
			this.bottomList = []
			this.current = 0
			this.type = 0
			this.getMyEvent()
			this.midButton = false
		},
		onHide() {

		},
		mounted() {
			this.getPersonInfo()
			this.getIndexInfo()
			this.eventNum()
			this.getMyTask()
			this.getMyTask2()
		},
		methods: {
			toPage(url) {
				uni.navigateTo({
					url: url,
					fail(r) {
						console.log(r)
					}
				})
			},
			// 巡查
			getMyTask() {
				let params = {
					taskType:2, // 巡查
				}
				this.$u.api.myTask(params)
					.then(res => {
						// console.log(res)
						if(res.code == 200) {
							this.targetXun = res.result.total
						}
					})
					.catch(err => {
						
					})
			},
			// 走访
			getMyTask2() {
				let params = {
					taskType:3, 
				}
				this.$u.api.myTask(params)
					.then(res => {
						// console.log(res)
						if(res.code == 200) {
							this.targetZou = res.result.total
						}
					})
					.catch(err => {
						
					})
			},
			handlemidButton(url) {
				uni.navigateTo({url})
			},
			// 去事件
			handleGoInfo(id) {
				uni.navigateTo({
					url: '../ThingsInfo/ThingsInfo?id=' + id
				})
			},
			eventNum() {
				this.$u.api.getEventNum()
					.then(res => {
						console.log(res)
						this.submitEventNum = res.result.submitEventNum
					})
					.catch(err => {
						console.log(err)
					})
			},
			// 事件列表
			getMyEvent(type) {
				let params = {
					type: this.type
				}
				this.$u.api.getMyEvent(params)
					.then(res => {
						// console.log(res)
						if (res.code == 200) {
							let type = ''
							let status = ''
							if (this.type == 0) {
								this.list[0].cate_count = res.result.records.length
							} else if (this.type == 1) {
								this.list[1].cate_count = res.result.records.length
							} else if (this.type == 2) {
								this.list[2].cate_count = res.result.records.length
							}
							res.result.records.forEach(item => {
								if (item.eventType == '' || item.eventType == null) {
									type = '暂无'
								}
								this.bottomList.push({
									id: item.id,
									title: item.title,
									listLeft: '执行人:管理员',
									listRight: '巡查时间:' + item.submitDate
								})
							})
						}
					})
					.catch(err => {
						console.log(err)
					})
			},
			change(index) {
				this.current = index
				this.type = index
				this.bottomList = []
				this.getMyEvent()

				// 全部
				if (index == 3) {
					uni.navigateTo({
						url: '../ThingsList/ThingsList'
					})
				}
			},
			getPersonInfo() {
				this.$u.api.PersonInfo()
					.then(res => {
						// console.log(res)
						if (res.code == 200) {
							let userType = res.result.mobileLonginUser.userType
							let type = ''
							if (userType.indexOf('1') >= 0) {
								type = '网格员';
							} else if (userType.indexOf('2') >= 0) {
								type = '护路员'
							} else if (userType.indexOf('3') >= 0) {
								type = '政法委员'
							} else if (userType.indexOf('4') >= 0) {
								type = '群防群治队员'
							} else if (userType.indexOf('5') >= 0) {
								type = '协警'
							} else if (userType.indexOf('6') >= 0) {
								type = '领导'
							} else if (userType.indexOf('7') >= 0) {
								type = '小区物业管理员'
							} else if (userType.indexOf('8') >= 0) {
								type = '楼栋长'
							}

							this.personInfo.name = res.result.mobileLonginUser.userRealname
							this.personInfo.userType = type
							this.personInfo.userImage = res.result.gridStaff.userHeadImg
							this.personInfo.groupName = res.result.gridStaff.gridName
							uni.setStorageSync("gridId", res.result.gridStaff.gridId)
							uni.setStorageSync("personalInfo", res.result.gridStaff)
						}
					})
					.catch(err => {
						console.log(err)
					})
			},
			getIndexInfo() {
				this.$u.api.indexInfo()
					.then(res => {
						// console.log(res)
						if (res.code == 200) {
							this.HeadList[0].num = res.result.buildingNum
							this.HeadList[1].num = res.result.houseNum
							this.HeadList[2].num = res.result.quartersNum
							this.HeadList[3].num = res.result.registerFamilyNum // 户籍
							this.HeadList[4].num = res.result.personNum
							this.HeadList[5].num = res.result.importantPersonNum
							this.HeadList[6].num = res.result.enterpriseNum
							this.HeadList[7].num = res.result.hospitalNum // 医院
							this.HeadList[8].num = res.result.campusNum //  学校
							this.HeadList[9].num = res.result.shopNum
							this.HeadList[10].num = res.result.publicTranNum
							// this.HeadList[11].num = res.result.publicTranNum // 铁路重点路段
						}
					})
					.catch(err => {
						console.log(err)
					})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.home-container {
		min-height: 100vh;
		background-color: #f5f6f7;
		position: relative;

		.midButton {
			width: 100%;
			min-height: 50vh;
			padding: 20rpx;

			.midbutton-cacel {
				width: 100%;
				padding: 20rpx 0;
				color: #000;
				font-size: 30rpx;
				font-weight: 600;
				text-align: center;
				border-top: 1px solid #f4f1f1;
			}

			.midButton-head {
				width: 100%;
				padding: 20rpx 0;
				color: #000;
				font-size: 30rpx;
				font-weight: 600;
				text-align: center;
			}

			.midbutton-content {
				display: flex;
				justify-content: flex-start;
				align-items: center;
				flex-wrap: wrap;
				padding: 20rpx 0;

				.midbutton-content-item {
					display: flex;
					justify-content: center;
					align-items: center;
					flex-direction: column;
					color: #333;
					font-size: 28rpx;
					width: 25%;
					margin: 10rpx 0;

					.item-top {
						width: 30px;
						height: 30px;
						margin-bottom: 10rpx;

						image {
							width: 30px;
							height: 30px;
						}
					}
				}
			}
		}

		.home-top {
			width: 100%;
			height: 30vh;
		}

		.home-content {
			position: absolute;
			top: 10rpx;
			left: 50%;
			width: 680rpx;
			min-height: 95vh;
			transform: translateX(-340rpx);

			.content-top {
				display: flex;
				justify-content: space-between;
				align-items: center;
				padding: 20rpx 20rpx 0 0;
				height: 200rpx;

				.top-left {
					display: flex;
					justify-content: center;
					align-items: center;

					.left-1 {
						width: 110rpx;
						height: 110rpx;

						image {
							border-radius: 50%;
						}
					}

					.left-2 {
						display: flex;
						justify-content: space-between;
						align-items: flex-start;
						flex-direction: column;
						height: 100rpx;
						margin-left: 20rpx;

						.left-2-top {
							display: flex;
							justify-content: flex-start;
							align-items: center;
							color: #fff;

							.left-2-top-1 {
								font-size: 30rpx;
								font-weight: 600;
							}

							.left-2-top-2 {
								font-size: 22rpx;
								background-color: rgba(255, 255, 255, 0.4);
								width: 180rpx;
								height: 35;
								border-radius: 20rpx;
								display: flex;
								justify-content: center;
								align-items: center;
								margin-left: 20rpx;
							}
						}

						.left-2-bottom {
							color: #fff;
							font-size: 24rpx;
							font-weight: 200;

							text {
								display: inline-block;
								margin-left: 10rpx;
							}
						}
					}
				}

				.top-right {
					display: flex;
					justify-content: space-around;
					align-items: flex-start;
					flex-direction: column;
					color: #fff;
					font-size: 30rpx;
					height: 100rpx;

					.top-right-1 {}

					.top-right-1 {}
				}
			}
		}

		.content-con1 {
			width: 100%;
			background-color: #fff;
			border-radius: 10rpx;
			box-shadow: 0 3px 3px #eee, 0 0 3px #eee, 0 0 3px #eee;
			margin-bottom: 30rpx;
			padding: 20rpx;

			.content-con1-head {
				color: #007AFF;
				font-size: 36rpx;
				font-weight: 600;
				padding: 10rpx 0;
			}

			.content-con1-con {
				display: flex;
				justify-content: flex-start;
				align-items: center;
				flex-wrap: wrap;
				.content-con1-con-item {
					width: 30%;
					height: 140rpx;
					border-radius: 12rpx;
					background-color: #e4f0fd;
					display: flex;
					justify-content: space-around;
					flex-direction: column;
					padding: 10rpx;
					margin-bottom: 20rpx;
					margin-right: 10rpx;
					margin-left: 10rpx;
					.item-top {
						display: flex;
						justify-content: flex-start;
						align-items: center;
						width: 100%;
						text-align: left;

						.item-top-img {
							width: 38rpx;
							margin-right: 8rpx;
						}

						.item-top-text {
							color: #333;
							font-size: 28rpx;
							letter-spacing: 2px;
						}
					}

					.item-bottom {
						color: #007AFF;
						font-weight: 600;
						font-size: 38rpx;
						width: 100%;
						text-align: center;
					}

				}
			}

			.content-con1-con2 {
				display: flex;
				justify-content: space-around;
				align-items: center;
				background-color: #fdf4e0;
				height: 140rpx;
				width: 100%;
				border-radius: 10rpx;
				margin: 10rpx 0;

				.content-con1-con2-item {
					display: flex;
					justify-content: center;
					align-items: center;
					flex-direction: column;

					.item-top:nth-child(1) {
						color: #f3ac43;
						font-size: 38rpx;
						font-weight: 600;
						margin-bottom: 10rpx;
					}

					.item-top:nth-child(2) {
						color: #333;
						font-size: 26rpx;
					}
				}
			}
		}

		.content-con2 {
			width: 100%;
			background-color: #fff;
			border-radius: 10rpx;
			box-shadow: 0 3px 3px #eee, 0 0 3px #eee, 0 0 3px #eee;
			margin-bottom: 20rpx;
			padding: 20rpx;
			min-height: 500rpx;

			.content-con2-head {}

			.none {
				color: #999;
				font-size: 30rpx;
				width: 100%;
				text-align: center;
				font-weight: 600;
				padding-top: 100rpx;
			}

			.content-con2-content {
				padding: 0 20rpx;

				.content-con2-content-item {
					display: flex;
					justify-content: space-around;
					align-items: flex-start;
					flex-direction: column;
					height: 120rpx;
					width: 100%;
					border-top: 1px solid #f4f1f1;
					padding: 10rpx 0;

					.item-top {
						color: #000;
						font-size: 30rpx;
						font-weight: 600;
					}

					.item-bottom {
						display: flex;
						justify-content: space-between;
						align-items: center;
						color: #999;
						font-size: 26rpx;
						width: 100%;

						.bottom-1 {}

						.bottom-2 {}
					}
				}
			}
		}
	}
</style>
